//
//  XMTabBarController.m
//  JHSwitchScreenDemo
//
//  Created by lishi on 2018/8/6.
//  Copyright © 2018年 JiehaoWu. All rights reserved.
//

#import "XMTabBarController.h"

#import "XMNaviagtionController.h"
#import "OneViewController.h"
#import "TwoViewController.h"

@interface XMTabBarController ()

@end

@implementation XMTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    // 首页
    [self addViewControllerClassName:[OneViewController description] imageName:@"icon_my" titles:@"首页" tabBarItemTag:100];
    
    //  我的
    [self addViewControllerClassName:[TwoViewController description] imageName:@"icon_my" titles:@"我的" tabBarItemTag:101];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 设置子控制器的图片和文字
- (void)addViewControllerClassName:(NSString *)className
                         imageName:(NSString *)imageName
                            titles:(NSString *)titles
                     tabBarItemTag:(NSInteger)tabBarItemTag{
    UIViewController *viewController = [[NSClassFromString(className) alloc]init];
    
    //系统返回手势
    XMNaviagtionController *stNavigation = [[XMNaviagtionController alloc] initWithRootViewController:viewController];
    
    stNavigation.tabBarItem.title = titles;
    stNavigation.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    stNavigation.tabBarItem.tag = tabBarItemTag;
    
    
    //拼接字符串
    //    stringByAppendingString
    stNavigation.tabBarItem.selectedImage = [[UIImage imageNamed:[imageName stringByAppendingString:@"_selected"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    //添加了子视图
    [self addChildViewController:stNavigation];
}

- (BOOL)shouldAutorotate{
    return [self.selectedViewController shouldAutorotate];
}
- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return [self.selectedViewController supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return [self.selectedViewController preferredInterfaceOrientationForPresentation];
}

- (UIViewController *)childViewControllerForStatusBarStyle {
    return self.selectedViewController;
}
- (UIViewController *)childViewControllerForStatusBarHidden {
    return self.selectedViewController;
}

@end
